<template>
  <div class="modify_date">
    <el-dialog
      title="修改送达时间"
      :visible.sync="modifyDialog"
      v-dialogDrag
      :close-on-click-modal="false"
      width="400px"
      customClass="mes_dialog"
      @closed="closeDialog">
      <div class="modify_cont">
        <span class="modify_label">要求送达时间：</span>
        <el-date-picker
          v-model="modifyTime"
          type="date"
          size="small"
          :editable="false"
          placeholder="请选择送达时间"
          value-format="yyyy-MM-dd 23:59:59"
          :picker-options="modifyPicker">
        </el-date-picker>
      </div>
      <div slot="footer" class="mes_btn">
        <el-button @click="confirmModify" type="primary">修改</el-button>
        <el-button @click="closeDialog">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'ModifyDate',
  props: {
    selectData: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      // 修改时间的dialog状态
      modifyDialog: false,
      // 修改的送达时间
      modifyTime: '',
    }
  },
  computed: {
    modifyPicker() {
      return {
        disabledDate: (time) => {
          return time.getTime() < this.$startTimeStamp(window.serverTime)
        }
      }
    }
  },
  methods: {
    // 修改希望送达时间
    confirmModify() {
      if (!this.modifyTime) {
        this.$message({
          type: 'error',
          message: '请选择修改时间',
          duration: 1500,
          center: true
        })
        return
      }
      let ids = this.selectData.map(item => item.id)
      this.$store.dispatch('saveData', {
        method: 'post',
        url: 'a/materialrequest/materialRequest/modifyexpectservicedate',
        data: {
          ids: ids.join(','),
          requireServiceDate: this.modifyTime
        },
        noCommit: true
      }).then(() => {
        this.closeDialog()
        this.$emit('refresh')
        this.$message({
          type: 'success',
          message: '修改成功',
          duration: 1500,
          center: true
        })
      })
    },
    // 打开弹框
    openDialog() {
      this.modifyDialog = true
    },
    // 关闭弹框
    closeDialog() {
      this.modifyDialog = false
      this.modifyTime = ''
    },
  }
}
</script>

<style lang="less">

</style>
